package com.taxi.comm.util;

import java.text.SimpleDateFormat;

/**
 * Date relative util class.
 * Including:
 * 	+ get a thread safe simple date format instance
 * 
 * @author Watertao
 *
 */
public class DateUtil {

	private static final ThreadLocal<SimpleDateFormat> dateFmt = new ThreadLocal<SimpleDateFormat>(){
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyyMMdd");
		}
	};
	
	private static final ThreadLocal<SimpleDateFormat> timeFmt = new ThreadLocal<SimpleDateFormat>(){
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("HHmmss");
		}
	};
	
	private static final ThreadLocal<SimpleDateFormat> datetimeFmt = new ThreadLocal<SimpleDateFormat>(){
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyyMMddHHmmss");
		}
	};
	

	/**
	 * Return a thread local simple date format instance, we can use this instance in multi-thread
	 * environment.
	 * The format string is 'yyyyMMdd'
	 * 
	 * @return
	 */
	public static SimpleDateFormat getDateFmt() {
		return dateFmt.get();
	}
	
	/**
	 * Return a thread local simple date format instance, we can use this instance in multi-thread
	 * environment.
	 * The format string is 'HHmmss'
	 * 
	 * @return
	 */
	public static SimpleDateFormat getTimeFmt() {
		return timeFmt.get();
	}
	
	/**
	 * Return a thread local simple date format instance, we can use this instance in multi-thread
	 * environment.
	 * The format string is 'yyyyMMddHHmmss'
	 * 
	 * @return
	 */
	public static SimpleDateFormat getDateTimeFmt() {
		return datetimeFmt.get();
	}
	
}
